package com.zzyl.nursing.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.MemberReservationService;
import com.zzyl.nursing.vo.TimeAndCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ZTtv
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private MemberReservationService memberReservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
       int count = memberReservationService.getCancelledReservationCount(userId);
        return R.ok(count);
    }
    @GetMapping("/countByTime")
    @ApiOperation("查询指定时间段预约数量")
    public R<List<TimeAndCountVo>> getCountByTime(Long time) {
        return R.ok(memberReservationService.getCountByTime(time));
    }
    @PostMapping
    @ApiOperation("新增预约")
    public AjaxResult addReservation(@RequestBody Reservation reservation) {
        memberReservationService.addReservation(reservation);
        return AjaxResult.success();
    }
    @GetMapping("/page")
    @ApiOperation("分页查询预约信息")
    public R<TableDataInfo<Reservation>> list(Integer pageSize, Integer pageNum){
        TableDataInfo<Reservation> page = memberReservationService.page(pageSize, pageNum);
        return R.ok(page);
    }
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancelReservation(@PathVariable Long id) {
        memberReservationService.cancelReservation( id);
        return AjaxResult.success() ;
    }
}